package com.work.controller;

import com.work.bean.HwAttach;
import com.work.dao.HwAttachDao;
import com.work.dao.impl.HwAttachDaoImpl;
import com.work.utils.WebUtils;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

public class HwAttachServlet extends BaseServlet{
    HwAttachDao hwAttachDao = new HwAttachDaoImpl();
    protected void queryHwAttach(HttpServletRequest req, HttpServletResponse resp) throws
            ServletException, IOException {
        List<HwAttach> hwAttachs = hwAttachDao.queryHwAttach();
        req.setAttribute("hwAttach",hwAttachs);
        req.getRequestDispatcher("/page/admin/admin_hw.jsp").forward(req,resp);
    }
    protected void queryHwAttachById(HttpServletRequest req, HttpServletResponse resp) throws
            ServletException, IOException {
        int id = WebUtils.parseInt(req.getParameter("id"),0);
        HwAttach hwAttach = hwAttachDao.queryHwAttachById(id);
        req.setAttribute("hwAttach",hwAttach);
        req.getRequestDispatcher("/page/admin/admin_hw.jsp").forward(req,resp);
    }
    protected void saveHwAttach(HttpServletRequest req, HttpServletResponse resp) throws
            ServletException, IOException {

    }
    protected void updateHwStu(HttpServletRequest req, HttpServletResponse resp) throws
            ServletException, IOException {
        int id = WebUtils.parseInt(req.getParameter("id"),0);
        HwAttach hwAttach = hwAttachDao.queryHwAttachById(id);
        req.setAttribute("hwAttach",hwAttach);
        req.getRequestDispatcher("/page/admin/admin_hw.jsp").forward(req,resp);
    }
    protected void deleteHwStu(HttpServletRequest req, HttpServletResponse resp) throws
            ServletException, IOException {
        int id = WebUtils.parseInt(req.getParameter("id"),0);
        hwAttachDao.deleteHwAttach(id);
        resp.sendRedirect(req.getContextPath() + "/HwAttachServlet?action=queryHwAttach");
    }
}
